package class41To50;

import java.io.*;

public class ArithmeticSequenceDifference {

    public static int n;

    public static int m;

    public static int MAX_N = 10000005;

    public static long[] arr = new long[MAX_N];

    public static int l;

    public static int r;

    public static int s;

    public static int e;

    public static int d;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int) in.nval;
        in.nextToken();
        m = (int) in.nval;
        for (int i = 0; i < m; i++) {
            in.nextToken();
            l = (int) in.nval - 1;
            in.nextToken();
            r = (int) in.nval - 1;
            in.nextToken();
            s = (int) in.nval;
            in.nextToken();
            e = (int) in.nval;
            d = (e - s) / (r - l);
            setVal();
        }
        build();
        long max = Integer.MIN_VALUE;
        long ret = 0;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, arr[i]);
            ret ^= arr[i];
        }
        out.println(ret + " " + max);
        out.flush();
        out.close();
        br.close();
    }

    private static void setVal() {
        arr[l] += s;
        arr[l + 1] += d - s;
        arr[r + 1] -= d + e;
        arr[r + 2] += e;
    }

    private static void build() {
        for (int i = 1; i < n; i++) {
            arr[i] += arr[i - 1];
        }
        for (int i = 1; i < n; i++) {
            arr[i] += arr[i - 1];
        }
    }
}
